import os, sys

# 导入其他模块文件
project_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../database"))
if project_path not in sys.path:
    sys.path.append(project_path)

import database.database_mysql as db
import akshare as ak
import datetime
import utils.date_util as dt
import pandas as pd


class Main:

    def __init__(self):
        # self.today = datetime.date.today()
        # stock_board_industry_columns = ['代码', '名称', '最新价', '涨跌幅', '涨跌额', '成交量', '成交额', '振幅', '最高',
        #                              '最低', '今开', '昨收', '量比', '换手率', '市盈率-动态', '市净率', '总市值', '流通市值',
        #                              '涨速', '5分钟涨跌', '60日涨跌幅', '年初至今涨跌幅']
        self.stock_board_industry_columns = ['code', 'name', 'zx_price', 'zd_range', 'zd_amt', 'cj_num', 'cj_amt',
                                          'zf', 'highest', 'lowest', 'jk', 'zs', 'lb', 'hs_rate', 'per', 'pbr', 'zsz',
                                          'ltsz', 'zs', 'zd_5', 'zd_60', 'zd_curr_year']

    def test(
            self,
            file_path: str,
            file_name: str = 'stock_data.xlsx'
    ) -> pd.DataFrame:
        stock_zh_a_spot_em_df = ak.stock_zh_a_spot_em()
        stock_zh_a_spot_em_df.to_excel(file_path + file_name, index=False)
        # stock_zh_a_spot_em_df.columns = self.stock_data_columns
        return stock_zh_a_spot_em_df



file_path = os.path.dirname(os.getcwd()) + '/file/data/'
file_name = 'stock_industry_hist_data.xlsx'
# print(file_path+file_name)
curr_date = dt.DateUtil().get_date_strftime(strftime='%Y%m%d')
# print(curr_date)

# main = Main()
# stock_data = main.stock_spot_data(file_path=file_path, file_name=file_name)

# stock_dict = stock_data.iloc[:, 1:2]
# stock_dict.columns = ['name', 'code']
# stock_data['type'] = '01'
# stock_data['name'] = '小金属'
# print(stock_dict)
# print(stock_dict, type(stock_dict))

# test = db.MySQLHandler()
# test.insert_batch_df(df=stock_data, table_name='stock_industry_his')

# stock_dict['板块名称'].apply(lambda x : main.stock_board_industry_hist_data(file_path=file_path, symbol = x, end_date=curr_date))

# stock_dict['板块名称'].apply(lambda x : test.insert_batch_df(df=main.stock_board_industry_cons_data(symbol = x),
#                                                  table_name='stock_industry_cons', symbol=x))


# data = {'Column1': ['000001', '000002', '000003', '000004'],
#         'Column2': [1, 2, 3, 4],
#         'Column3': ['A', 'B', 'C', 'D']}
# df = pd.DataFrame(data)
# # data = [tuple(x) for x in df.values]
# print([tuple(x) for x in df.values])
# print(df['Column1'].dtypes)
# df['Column1'] = df['Column1'].astype(str)

